package com.jm3.riscar3.memory;

public class InstructionRegister extends Register {

	private int dataLow;
	
	public InstructionRegister()
	{
		super();
		dataLow = 0;
	}
	
	public void writeRegisterLow(int newData)
	{
		dataLow = newData;
	}
	
	public int readRegisterLow()
	{
		return dataLow;
	}
	
	public String getInstructionOpCode()
	{
		String binaryHighByte = Integer.toBinaryString(this.readRegister());
		while(binaryHighByte.length() < 8) { binaryHighByte = "0" + binaryHighByte; }
		return binaryHighByte.substring(0, 5);
	}
	
	public String getArguments()
	{
		String binaryHighByte = Integer.toBinaryString(this.readRegister());
		String binaryLowByte = Integer.toBinaryString(this.readRegisterLow());
		String binaryCommand;
		
		while(binaryHighByte.length() < 8) { binaryHighByte = "0" + binaryHighByte; }
		while(binaryLowByte.length() < 8) { binaryLowByte = "0" + binaryLowByte; }
		
		binaryCommand = binaryHighByte + binaryLowByte;
		return binaryCommand.substring(5);
		
	}
	
}
